﻿/**
 * 提示框
 * 
 * @author luo
 * @email luo4521@online.net.tw
 * 2010-1-28 10:34
 */
package com.addcn.texas.view.components
{
	import fl.transitions.easing.Strong;
	import flash.display.MovieClip;
	import flash.display.*;
	import flash.events.*;
	import flash.text.TextField;
	

	
	public class PopupWindow extends winBase
	{		
		public static const OK_EVENT : String = "OKEvent";		
		public static const NO_EVENT : String = "NOEvent";
		public static const ALERT : String = "alert";
		public static const SELECT : String = "select";
		public static const NOTICE : String = "notice";
		private var _type : String;
		private var _msg : String;
		private var _ok_btn : DisplayObject;
		private var _no_btn : DisplayObject;
		private var _parent : Object;
		
		function PopupWindow(r_parent : Object ,r_type : String = 'alert') : void {	
			this._parent = r_parent;
			this._type = r_type;		
			_init();			
		}		
		
		private function _init() : void {	
			this.drag(this['bg']);						
			if (this._type == PopupWindow.ALERT) {
				_ok_btn  = new OKButton;
				_ok_btn.name = PopupWindow.OK_EVENT;
				this.addChild(_ok_btn);
				_ok_btn.x = 197;
				_ok_btn.y = 150;
				_ok_btn.addEventListener(MouseEvent.CLICK, _btnClickHandler);
			}else if(this._type == PopupWindow.SELECT){
				_ok_btn  = new OKButton;
				_no_btn = new NOButton;
				_ok_btn.name = PopupWindow.OK_EVENT;
				_no_btn.name = PopupWindow.NO_EVENT;
				this.addChild(_ok_btn);
				this.addChild(_no_btn);
				_ok_btn.x = 128;
				_ok_btn.y = 150;
				_no_btn.x = 259;
				_no_btn.y = 150;
				_ok_btn.addEventListener(MouseEvent.CLICK, _btnClickHandler);
				_no_btn.addEventListener(MouseEvent.CLICK, _btnClickHandler);
			}			
					
		}
		
		public function set msg(r_msg : String) : void {
			this._msg = r_msg;
			this["notice"].text = this._msg;
		}
		
		public function show() {			
			if(this._parent != null){
				this._parent.addChild(this);	
				this.x = (this._parent.stage.stageWidth -this.width)/ 2;
				this.y = (this._parent.stage.stageHeight - this.height) / 2;					
			}
		}
		
		public override function remove() :void {
			super.remove();			
			this.parent.removeChild(this);
			
		}
		
		private function _btnClickHandler(evt : Event) : void {
			if (_no_btn) {
				_no_btn.removeEventListener(MouseEvent.CLICK,_btnClickHandler);
			}
			if(_ok_btn){
				_ok_btn.removeEventListener(MouseEvent.CLICK, _btnClickHandler);
			}
			this.remove();			
			var event : Event = new Event(evt.target.name);
			this.dispatchEvent(event);
		}
		
	}
	
}
